# Maintainer: Yusuke Sasaki <y_sasaki@nuem.nagoya-u.ac.jp>

_realname=potrace
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.16
pkgrel=1
pkgdesc="Tool for tracing a bitmap, which means, transforming a bitmap into a smooth, scalable image (mingw-w64)"
arch=('any')
url='https://potrace.sourceforge.io/'
license=('GPL2')
source=("https://potrace.sourceforge.io/download/${pkgver}/${_realname}-${pkgver}.tar.gz"
        001-reaarange-compiler-detect.patch)
sha256sums=('be8248a17dedd6ccbaab2fcc45835bb0502d062e40fbded3bc56028ce5eb7acc'
            '17a46071e826fd2f2715c63002ff6ddb2635f40b44ceb88fec9bdb5f4d61e1ea')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-reaarange-compiler-detect.patch
  autoreconf -fiv
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  ../${_realname}-${pkgver}/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --mandir=${MINGW_PREFIX}/share/man \
    --enable-shared \
    --enable-static \
    --with-libpotrace
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
